import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from './../views/home/Home'
const Home= ()=> import('@/views/home/Home')
const About= ()=> import('./../components/About.vue')
const PlayList= ()=> import('./../components/PlayList.vue')
const Detail= ()=> import('./../components/content/Detail.vue')
Vue.use(VueRouter)
const routes=[
    { path:"/",redirect:'/home',meta: { title: '网抑云音乐' } },
    { path:"/home",component:Home,meta: { title: '网抑云音乐' } },
    { path:"/about",component:About,meta: { title: '关于' } },
    { path:"/top/playlist",component:PlayList,meta: { title: '列表' } },
    { path:"/playlist/detail",component:Detail,meta: { title: '详情' } },
]
const router=new VueRouter({
    routes
})
router.beforeEach((to,from,next)=>{
    document.title=to.meta.title
    router.app.$options.store.commit('hideCpn','isShowLogin')
    // console.log(this,999);//路由守卫没有this
    if(to.path=='/login' || to.path=='/register' || to.path=='/home'){
        router.app.$options.store.commit('hideCpn','isShowTips')
        next()
    }else{
        if(!localStorage.userInfo){//进入想要提示的路由时，如果没有登录 则显示tips组件
            router.app.$options.store.commit('showCpn','isShowTips')
            // router.app.$toast('你还没有登录哦')
        }
        // alert('请登录')
        next()
    }
})
export default router;